package com.voice.client.channel.handle.impl;

import com.voice.client.channel.handle.StreamListenerHandler;
import com.voice.core.connection.Connection;
import com.voice.core.connection.ConnectionListener;
import com.voice.core.connection.ConnectionStatus;
import com.voice.core.connection.callback.AbstractStreamListener;
import com.voice.core.connection.entity.Stream;
import com.voice.core.connection.entity.StreamData;
import com.voice.core.entity.HttpHeader;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class AbstractStreamListenerHandler<T extends Connection> extends AbstractStreamListener<T> implements StreamListenerHandler<T>, ConnectionListener<T>{

    @Override
    public void handle(HttpHeader requestHeader, Connection connection){
        T  t = conversionTo(requestHeader,connection);
        t.setDefaultStreamListener(this);
        t.setConnectionListener(this);
        t.setStatus(ConnectionStatus.AUTHORIZED);
    }

    public abstract T conversionTo(HttpHeader requestHeader, Connection connection);

    @Override
    public void onStreamRead(T connection, byte[] bytes) { }

    @Override
    public void onDataRead(T connection, Stream stream, StreamData streamData) {}

}
